<?php
$this->Html->addCrumb('Services', '/admin/services');
$this->Html->addCrumb('Edit');
$this->Html->scriptStart(array('inline' => false));
echo '
      $(function(){
        $("#ServiceAdminEditForm").TWS_Form( {
          validate : {
          rules : {
            ServiceName : {required : true, help : "This is the name for the service"},
            ServiceIntroduction : {required : true, help : "This is the introduction text that is displayed describing the service"},
            ServiceImagePath : {help : "This image will be displayed on the service introduction page"},
            ServiceDetail : {help : "Additional details about the service here will be displayed on a separate page"},
            ServiceImagedetail1Path : {help : "This image will be displayed along with the additional service details on a separate page"},
            ServiceImagedetail2Path : {help : "This image will be displayed along with the additional service details on a separate page"},
            ServiceImagedetail3Path : {help : "This image will be displayed along with the additional service details on a separate page"}
          }
          }});
     
         $("#deleteBtn").click(function(event){
          if(!$("#deleteBtn").attr("data-delete-confirm")) {
          $("#deleteBtn").attr("data-delete-confirm","");
            $.TWS_Overlay("confirm", {title : "Delete confirmation", message : "Are you sure you want to delete this service? <br/><br/>Please note all Companies linked to this service will also be deleted!", buttons : {ok :{onclick : function () { $.TWS_Overlay("hide"); $("#deleteBtn").attr("data-delete-confirm",true).trigger("click");}}}});
            event.preventDefault();
          }
        });
         $(".deleteImage").click(function(event){
            var $link = $(this);
            $.TWS_Overlay("confirm", {title : "Delete confirmation", message : "Are you sure you want to delete this image?", buttons : {ok :{onclick : function () { $.TWS_Overlay("hide"); location.href=$link.attr("href");}}}});
            event.preventDefault();          
        });
      });
       ';
$this->Html->scriptEnd();

?>


<h1>Edit Service</h1>
<?php echo $this->Session->flash();?>
<?php echo '<div id="actionLink">'.$this->Html->link('Back to list of Services',array('action'=>'index', 'admin'=>true)).'</div>'; ?>

<?php echo $this->element('errors', array('errors' => isset($errors)? $errors : null)); ?>
<?php

echo $this->TWSForm->create('Service',  array(
    'inputDefaults' => array(
        'div' => array('class'=>'row')),
        'class'=>'inlineForm',
        'type'=>'file'));
echo '<p>These will be displayed on the initial services page. Additional details about the service can be specified below.</p>';
echo $this->TWSForm->input('name', array('name'=>'ServiceName', 'size'=>'63', 'type'=>'text', 'label'=>'<span class="required">*</span>Name'));
echo $this->TWSForm->input('introduction', array('rows'=>'10','cols'=>'60','name'=>'ServiceIntroduction', 'label'=>'<span class="required">*</span>Introduction'));


$record = $this->request->data['Service'];
if(!empty($record['image_path'])){
  echo '<p>'.$this->Html->image($record['image_path'], array('alt' => $record['name'])).'</p>';
  echo '<p>'.$this->Html->link('Delete image', array('controller' => 'services', 'action' => 'deleteMainImage', 'admin'=>true, $record['id']), array("title"=>"Delete this image" , "class"=>"deleteImage")).'</p>';
  echo $this->TWSForm->input('_image_path', array('type'=>'hidden', 'name'=>'_image_path', 'value'=>$record['image_path']));
  } else {
  echo $this->TWSForm->input('image_path', array('type'=>'file', 'label'=>'Upload image', 'name'=>'ServiceImagePath'));
}

echo '<hr/>';
echo '<p>The field and images below here will be displayed on a separate details page.</p>';
echo $this->TWSForm->input('detail', array('rows'=>'10','cols'=>'60','name'=>'ServiceDetail', 'label'=>'<span class="required">*</span>Additional Details'));

if(!empty($record['imagedetail1_path'])){
  echo '<p>'.$this->Html->image($record['imagedetail1_path'], array('alt' => $record['name'])).'</p>';
  echo '<p>'.$this->Html->link('Delete image', array('controller' => 'services', 'action' => 'deleteDetailImage1', 'admin'=>true, $record['id']), array("title"=>"Delete this image" , "class"=>"deleteImage")).'</p>';
  echo $this->TWSForm->input('_imagedetail1_path', array('type'=>'hidden', 'name'=>'_imagedetail1_path', 'value'=>$record['imagedetail1_path']));
  } else {
  echo $this->TWSForm->input('imagedetail1_path', array('type'=>'file', 'label'=>'Upload image', 'name'=>'ServiceImageDetail1Path'));
}

if(!empty($record['imagedetail2_path'])){
  echo '<p>'.$this->Html->image($record['imagedetail2_path'], array('alt' => $record['name'])).'</p>';
  echo '<p>'.$this->Html->link('Delete image', array('controller' => 'services', 'action' => 'deleteDetailImage2', 'admin'=>true, $record['id']), array("title"=>"Delete this image" , "class"=>"deleteImage")).'</p>';
  echo $this->TWSForm->input('_imagedetail2_path', array('type'=>'hidden', 'name'=>'_imagedetail2_path', 'value'=>$record['imagedetail2_path']));
  } else {
  echo $this->TWSForm->input('imagedetail2_path', array('type'=>'file', 'label'=>'Upload image', 'name'=>'ServiceImageDetail2Path'));
}

if(!empty($record['imagedetail3_path'])){
  echo '<p>'.$this->Html->image($record['imagedetail3_path'], array('alt' => $record['name'])).'</p>';
  echo '<p>'.$this->Html->link('Delete image', array('controller' => 'services', 'action' => 'deleteDetailImage3', 'admin'=>true, $record['id']), array("title"=>"Delete this image" , "class"=>"deleteImage")).'</p>';
  echo $this->TWSForm->input('_imagedetail3_path', array('type'=>'hidden', 'name'=>'_imagedetail3_path', 'value'=>$record['imagedetail3_path']));
  } else {
  echo $this->TWSForm->input('imagedetail3_path', array('type'=>'file', 'label'=>'Upload image', 'name'=>'ServiceImageDetail3Path'));
}

echo $this->TWSForm->submit('Update', array('id'=>'editBtn', 'name'=>'editBtn', 'class'=>'button', 'div'=>false));
echo $this->TWSForm->submit("Delete", array('id'=>'deleteBtn','name'=>'deleteBtn', 'class'=>'button', 'div'=>false));
echo $this->TWSForm->end();

?>